<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传</title>
    <style>
      #upload {}
    </style>
  </head>

  <body>
    <input type="file" id="file">
    <div id="upload">
      本地上传
    </div>
    <script type="text/javascript" src="https://www.xazhsq.cn/uni.webview.1.5.6.js"></script>
    <script>
      document.addEventListener('UniAppJSBridgeReady', function() {
        const uploadId = document.getElementById('upload')
        uploadId.onclick = () => {
          console.log('hihihi')
          uni.postMessage({
            data: {
              fileName: '999',
              fullPath: '9999'
            },
          })
        }

        //   const $fileInput = document.getElementById('file')
        //   const $uploadBtn = document.getElementById('upload')
        //   $uploadBtn.onclick = () => {
        //     $fileInput.click();
        //   }
        //   $fileInput.onchange = (e) => {
        //     const file = $fileInput.files[0]
        //     console.log(file)

        //     var formData = new FormData();
        //     formData.append('file', file);

        //     const query = location.search.substr(1)
        //     const queryArr = query.split('=')
        //     console.log(queryArr[1])
        //     var xhr = new XMLHttpRequest();
        //     xhr.open('POST', 'xx.xx.xx.xx:8080/file/upload');
        //     xhr.setRequestHeader('token', queryArr[1]);
        //     xhr.send(formData);
        //     xhr.onreadystatechange = function() {
        //       if (xhr.readyState == 4 && xhr.status == 200) {
        //         const resObj = JSON.parse(xhr.responseText)
        //         uni.postMessage({
        //           data: {
        //             fileName: resObj.data.fileName,
        //             fullPath: resObj.data.fullPath
        //           },
        //         })
        //       } else {
        //         console.log(xhr.statusText);
        //       }
        //     }
        //   }
      })
    </script>
  </body>
</html>